// 切换登录方式
$('.ways > li').on('click', function () {
    $(this).addClass('active').siblings().removeClass('active')
    // 盒子的功能实现
    $('.inner > div').removeClass('active').eq($(this).index() + 1).addClass('active')
})
$('.quick').on('click',function(){
    $('.inner').addClass('active')
    $('.register').addClass('active')
})

$('.register1 div').on('click', function () {

    $(this).addClass('active').siblings().removeClass('active')

    $('.register > form').removeClass('active').eq($(this).index()).addClass('active')

})


//注册验证
let form1 = document.querySelector('.form1')
//获取用户名 form1
let form1_1 = document.querySelector('.form1 input:nth-of-type(1)')
//账号
let form1_2 = document.querySelector('.form1 input:nth-of-type(2)')
//密码
let form1_3 = document.querySelector('.form1 input:nth-of-type(3)')
//重复密码
let form1_4 = document.querySelector('.form1 input:nth-of-type(4)')
// console.log(form1_1);
form1.onsubmit = function (e) {

    try {
        e.preventDefault()
    } catch (err) {
        e.returnValue = false
    }
    let username = form1_1.value
    let free = form1_2.value
    let password = form1_3.value
    let rpassword = form1_4.value

    let info1 = {
        username, 
        free,
        password,
        rpassword, 
    }
    if (!info1.username || !info1.free || !info1.password || !info1.rpassword) return alert('请输入账号')
    // 新密码和重复新密码要相同
    if (info1.password !== info1.rpassword) return alert('密码不一致')
    alert('我记住你了')

    
// 记录注册信息
    window.sessionStorage.setItem('username', info1.username)
    window.sessionStorage.setItem('free', info1.free)
    window.sessionStorage.setItem('password', info1.password)
    window.sessionStorage.setItem('rpassword', info1.rpassword)

    window.location.reload()

}
let mail1 = window.sessionStorage.getItem('e-mail')
let username1 = window.sessionStorage.getItem('username')
let free1 = window.sessionStorage.getItem('free')
let password1 = window.sessionStorage.getItem('password')
let rpassword1 = window.sessionStorage.getItem('rpassword')

let info1 = {
    mail1,
    username1, 
    free1,
    password1, 
    rpassword1, 
}
console.log(info1);
//注册验证
let form2 = document.querySelector('.form2')
//手机号
let phone2 = document.querySelector('.form2 input:nth-of-type(1)')
//获取用户名 form2
let form2_1 = document.querySelector('.form2 input:nth-of-type(2)')
//账号
let form2_2 = document.querySelector('.form2 input:nth-of-type(3)')
//密码
let form2_3 = document.querySelector('.form2 input:nth-of-type(4)')
//重复密码
let form2_4 = document.querySelector('.form2 input:nth-of-type(5)')
// console.log(form2_1);
form2.onsubmit = function (e) {

    try {
        e.preventDefault()
    } catch (err) {
        e.returnValue = false
    }
    let phone = phone2.value
    let username = form2_1.value
    let free = form2_2.value
    let password = form2_3.value
    let rpassword = form2_4.value

    let info2 = {
        phone,
        username, 
        free,
        password, 
        rpassword, 
    }
    if (!info2.username || !info2.free || !info2.password || !info2.rpassword) return alert('请输入账号')
    // 新密码和重复新密码要相同
    if (info2.password !== info2.rpassword) return alert('密码不一致')
   

    alert('我记住你了')
    window.sessionStorage.setItem('phone', info2.phone)
    window.sessionStorage.setItem('username1', info2.username)
    window.sessionStorage.setItem('free1', info2.free)
    window.sessionStorage.setItem('password1', info2.password)
    window.sessionStorage.setItem('rpassword1', info2.rpassword)

    window.location.reload()

}
let phone = window.sessionStorage.getItem('phone')
let username2 = window.sessionStorage.getItem('username1')
let free2 = window.sessionStorage.getItem('free1')
let password2 = window.sessionStorage.getItem('password1')
let rpassword2 = window.sessionStorage.getItem('rpassword1')


let info2 = {
    phone,
    username2,
    free2,
    password2,
    rpassword2
}
console.log(info2);


//邮箱
let mb1 = document.querySelector('.mailform1')

mb1.onsubmit = function (e) {
    try {
        e.preventDefault()
    } catch (err) {
        e.returnValue = false
    }
    console.log('aaa');
    let username1 = window.sessionStorage.getItem('username')
    let free1 = window.sessionStorage.getItem('free')
    let password1 = window.sessionStorage.getItem('password')
    let rpassword1 = window.sessionStorage.getItem('rpassword')

    //获取用户输入的值
    let mb2 = document.querySelector('.mailform1 > input:nth-of-type(1)')
    let mb3 = document.querySelector('.mailform1 > input:nth-of-type(2)')

    let mail = mb2.value
    let mail1 = mb3.value

    let info = {
        username1, //用户名
        free1,//账号
        password1, //密码
        rpassword1, //确认密码
    }
    console.log(username1, free1, password1, rpassword1);
    if ( !info.free1 || !info.password1 ) return alert('内容不能为空')
    if (mail === free1 && mail1 === password1) {
        alert('恭喜你，登录成功')
        window.location.href = './list.html'
    }else if(mailbox != free1){
        alert('账号输入错误')
    }else if(mailbox1 != password1){
        alert('密码输入错误')
    }
}

//手机号登录
let mp = document.querySelector('.mp1')

mp.onsubmit = function (e) {
    try {
        e.preventDefault()
    } catch (err) {
        e.returnValue = false
    }
    let phone = window.sessionStorage.getItem('phone')
    let username2 = window.sessionStorage.getItem('username1')
    let free2 = window.sessionStorage.getItem('free1')
    let password2 = window.sessionStorage.getItem('password1')
    let rpassword2 = window.sessionStorage.getItem('rpassword1')

    //获取用户输入的值
    let mp1 = document.querySelector('.mp1 > input:nth-of-type(1)')
    let mp2= document.querySelector('.mp1 > input:nth-of-type(2)')

    let mp3 = mp1.value
    let mp4 = mp2.value

    let info1 = {
        phone,
        username2, //用户名
        free2,//账号
        password2, //密码
        rpassword2, //确认密码
    }
    if (!info1.password2 || !info1. phone) return alert('内容不能为空')
    console.log(username1, free1, password1, rpassword1);
    if (mp3 === phone && mp4 === password2) {
        alert('恭喜你，登录成功')
        window.location.href = './list.html'
    }else if(mp3 != phone){
        alert('手机号输入错误')
    }else if(mp4 != password2){
        alert('密码输入错误')
    }
}

